

package com.sfac.javaSpringBoot.modules.common.entity;

import com.fasterxml.jackson.annotation.JsonFormat;

/**
 * 枚举
 */
@JsonFormat(shape= JsonFormat.Shape.OBJECT)//带属性的进行，否则返回值只是名字
public enum ImageType {
    //小图
    SMALL_IMAGE("small-image", 128, 128, 50),
    //中图
    MIDDLE_IMAGE("middle-image", 170, 170, 100),
    //大图
    BIG_IMAGE("big-image", 220, 220, 200),//200代表的200kb大小的图片
    ;
    public String name;
    public int length;//长
    public int width;//宽
    public int size;//尺寸

    /**
     * 构造器
     */
    ImageType(String name, int length, int width, int size) {
        this.name = name;
        this.length = length;
        this.width = width;
        this.size = size;
    }

    public static ImageType getImageTypeByName(String imageTypeName) {
        for (ImageType imageType : ImageType.values()) {
            if (imageType.name.equals(imageTypeName)) {
                return imageType;
            }
        }
        return null;
    }

    public static void main(String[] args) {
        System.out.println(ImageType.getImageTypeByName("middle-image"));
    }
}
